package com.baseDemo.web.dao.user.impl;

import java.util.HashMap;
import java.util.Map;

import org.springframework.stereotype.Repository;

import com.baseDemo.web.dao.user.UserEntityDao;
import com.baseDemo.web.entity.UserEntity;
import com.share.hibernate.baseDaoSupport.impl.BaseDaoHibernateSupport;
@Repository
public class UserEntityDaoHibernate extends BaseDaoHibernateSupport<UserEntity> implements UserEntityDao{

	@Override
	public UserEntity getByUsername(String userName, String password) {
		final String HQL="from UserEntity where loginID=:loginID and password=:password";
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("loginID", userName);
		map.put("password", password);
		return super.get(HQL,map);
	}

	@Override
	public UserEntity getByUsername(String userName) {
		final String HQL="from UserEntity where loginID=:loginID";
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("loginID", userName);
		return super.get(HQL,map);
	}

	@Override
	public Integer getPageTotal() {
		String HQL = " SELECT COUNT(id) FROM UserEntity as UE ";
		return this.getAgg(HQL);
	}

	@Override
	public String updatePassword(String password, String id) {
		String HQL = "UPDATE UserEntity ue SET ue.password=:password where ue.id = :id ";
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("password", password);
		map.put("id", id);
		return super.execute(HQL, map);
	}


}
